#include <iostream>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

void* task(void* x)
{
	int* temp;
	temp = static_cast<int *>(x);

	for (int i = 0; i < *temp; ++i)
	{
		cout<< "work from thread: " << i << endl;
	}
	cout<< "thread complete" << endl;

	return NULL;
}

int main(int argc, char const *argv[])
{
	int n;
	pthread_t threads[10];
    if (argc != 2)
    {
		printf("%s\n", argv[0]);
    	cout << "error" << endl;
    	exit(1);
    }

    n = atoi(argv[1]);

    if (n > 10)
    	n = 10;

    for (int i = 0; i < n; ++i)
    {
    	pthread_create(&threads[i], NULL, task, &n);
    }

    for (int i = 0; i < n; ++i)
    {
    	pthread_join(threads[i], NULL);
    }

	return 0;
}
